define(['request','template','swiper','jquery'], (request,template,Swiper) => {
    class Header {
      constructor () {
       
        this.load().then(() => {
          // 执行加载成功之后的逻辑
          this.search()
          this.getTabs()
          this.calcCartNum()
          this.Swiper()
         
        })
      }
  
      // 加载头部html
      load () {
        return new Promise(resolve => {
          // 加载成功之后resolve
          $('header').load('/html/modules/header.html', resolve)
        })
        
      }
     
      // 完成搜索功能
      search () {
        this.$input = $('#constyle')
        
        this.$input.on('keyup', () => {
          console.log(this.$input.val())
          // TODOS：jsonp接口
        })
      }
    
    getTabs(){
      request.getTabs().then(resp=>{
       
        if(resp.code===200){
         let { list }=resp.data
         list=list.slice(1,7)
         
         $('#tabList').append(template('tabsTemplate',{list}))
        }
      
      })
    }
    calcCartNum() {
      let cartList = localStorage.getItem('cart')
      if (cartList) {
          cartList = JSON.parse(cartList)
          let num = cartList.reduce((total, cart) => {
              total += cart.num
              return total;
          }, 0)
          $('#shopNum').html("(" + num + ")")
      } else {
          $('#shopNum').html("(" + 0 + ")")
      }
  }
    
  Swiper(){
    var mySwiper =new Swiper('.swiper-container', {
      direction: 'vertical', // 垂直切换选项
      loop: true, // 循环模式选项)
      autoplay:{
        reverseDirection: true,
      },
  })
 
  
   }
  }
    return new Header()
  });